package testView;

import static org.junit.Assert.*;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

import model.AnchorPoint;
import model.ClassImpl;
import model.RelationshipImpl;

/**
*   @version Iteration 3 March 21, 2011
*	@author Team EBE
*	CSCI 420 UML Diagram Software Engineering Project
*
*	Tests the relationshipTest.java Models
*	Specifically, this tests the construction of a new class, 
*	setting size, resizing, and adding attributes and operations
*	to populate the class. 
*/

public class relationshipTest {
	//global variable
	public RelationshipImpl testRel;
	
/**
*	This method tests the relationship constructor
*	and assigning a source and destination for the
*	relationship. It also test the setters and getters
*	for the relationship.
*/
	@Test
	public void test() {
		// Declare test variables.
		int test1 = 10;
		int test2 = 15;
		int test3 = 12;
		int test4 = 14;

		AnchorPoint testSrc = new AnchorPoint(0, 1, "test1", 0);
		AnchorPoint testDest = new AnchorPoint(2, 3, "test2", 1);

		// Test constructor
		testRel = new RelationshipImpl(testSrc, testDest);

		assertEquals(testRel.getSrc(), testSrc);
		assertEquals(testRel.getDest(), testDest);

		// Test setters and getters for multiplicity
		testRel.setDestMax(test2);
		testRel.setDestMin(test1);

		testRel.setSrcMax(test4);
		testRel.setSrcMin(test3);

		assertEquals(testRel.getDestMax(), test2);
		assertEquals(testRel.getDestMin(), test1);

		assertEquals(testRel.getSrcMax(), test4);
		assertEquals(testRel.getSrcMin(), test3);
	}
	
/**
*	This method is similar to the above test.
*	However, in addition, it tests the saveString 
*	function. It helps to prove that the data the 
*	user expects to be saved in a string is saved 
*	correctly. It also tests the setters and getters
*	for the srcMin, srcMax, destMin, and destMax. It
*	also tests setting and getting the relationship
*	type.
*/
	public void testSetGet(){
		
		int srcMin = 0;
		int srcMax = 1;
		int destMin = 2;
		int destMax = 3;
		String type = "Aggregation";

		// Create new test Classes
		AnchorPoint testSrc1 = new AnchorPoint(0, 1, "Test 3", 2);
		AnchorPoint testDest1 = new AnchorPoint(2, 3, "Test 4", 3);
		
		testRel = new RelationshipImpl(testSrc1, testDest1);
		
		// Test setter and getter for src and dest (AnchorPoints)
		testRel.setDest(testDest1);
		testRel.setSrc(testSrc1);

		assertEquals(testRel.getSrc(), testSrc1);
		assertEquals(testRel.getDest(), testDest1);
		
		// Test setter and getter for srcMin and Max
		
		testRel.setSrcMin(srcMin);
		testRel.setSrcMax(srcMax);
		testRel.setDestMin(destMin);
		testRel.setDestMax(destMax);
		testRel.setType(type);
		
		assertEquals(testRel.getSrcMin(), srcMin);
		assertEquals(testRel.getSrcMax(), srcMax);
		assertEquals(testRel.getDestMin(), destMin);
		assertEquals(testRel.getDestMax(), destMax);
		assertEquals(testRel.getType(), type);

		// tests saveString
		assertEquals(testRel.saveString(), "Test 3 Test 4\n");
	}
}
